<link type="text/css" rel="stylesheet" href="<?php echo $this->basePath('public/css/dbblack/css/ucenter.css'); ?>" />

<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/artDialog.js?skin=simple'); ?>"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $this->basePath('public/css/dbblack/js/form/style.css'); ?>"/>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/form/form.js'); ?>"></script>
<script type="text/javascript" charset="UTF-8" src="<?php echo $this->basePath('public/css/dbblack/js/jquery.iframe-post-form.js'); ?>"></script>

<div class="container clearfix">
  <?php echo $this->partial('shopfront/home/left_menu.phtml'); ?>
  <div class="content clearfix uc-content">
    <h1 class="title"><span><?php echo $this->translate('个人资料'); ?>：</span></h1>
    <?php if ($this->success_msg != '') { ?>
      <div class="message_success ie6png"><?php echo $this->success_msg; ?></div>
    <?php } ?>
    <div class="mt10" style="position:relative;">
      <form id="info-form" class="simple" enctype="multipart/form-data" method="post" callback="checkForm">
        <div style="position: absolute;top:10px;right: 10px;">
          <?php if(isset($this->user_info) and !empty($this->user_info->user_avatar)) { ?>
            <img id="head-pic" class="ie6png" src="<?php echo $this->basePath($this->user_info->user_avatar); ?>" width="120" height="120">
            <input type="hidden" name="old_user_avatar" id="old_user_avatar" value="<?php echo $this->user_info->user_avatar; ?>" />
          <?php } else { ?>
            <img id="head-pic" class="ie6png" src="<?php echo $this->basePath($this->frontwebsite()->getUserIni('default_avatar')); ?>" width="120" height="120">
          <?php } ?>
          <p style="padding: 10px 30px;"><input type="file" name="user_avatar" id="user_avatar"></p>
        </div>
        <table class="form">
          <tr><td class="label"><?php echo $this->translate('用户名称'); ?>：</td><td><input type="text" name="user_name" disabled readonly value="<?php echo $this->escapeHtml($this->user_info->user_name); ?>"></td></tr>
          <tr><td class="label"><?php echo $this->translate('会员分组'); ?>：</td><td><?php echo $this->user_group->group_name; ?></td></tr>
          <?php
          $userEmailRegisterState = $this->frontwebsite()->getRegOrLoginIni('register_email_state');
          $userPhoneRegisterState = $this->frontwebsite()->getRegOrLoginIni('register_phone_state');
          ?>
          <tr>
            <td class="label"><?php echo $this->translate('电子邮箱'); ?>
              <?php if ($userEmailRegisterState == 'true') { ?>
                <span class="must_add_value">*</span>
              <?php } ?>
              ：</td><td><input type="text" pattern="email" <?php echo $userEmailRegisterState == 'true' ? '' : 'empty=""'; ?> name="user_email" id="user_email" value="<?php echo $this->escapeHtml($this->user_info->user_email); ?>" alt="邮箱格式错误"> <label></label></td>
          </tr>
          <tr>
            <td class="label"><?php echo $this->translate('性别'); ?>：</td><td>
              <select id="user_sex" name="user_sex" class="span2">
                <option value="3" <?php if($this->user_info and $this->user_info->user_sex==3) { echo 'selected="selected"'; } ?>><?php echo $this->translate('保密'); ?></option>
                <option value="1" <?php if($this->user_info and $this->user_info->user_sex==1) { echo 'selected="selected"'; } ?>><?php echo $this->translate('男'); ?></option>
                <option value="2" <?php if($this->user_info and $this->user_info->user_sex==2) { echo 'selected="selected"'; } ?>><?php echo $this->translate('女'); ?></option>
              </select>
            </td>
          </tr>
          <tr>
            <td class="label"><?php echo $this->translate('生日'); ?>：</td><td><input name="user_birthday" id="user_birthday" type="text" onclick="WdatePicker({el:'user_birthday'})" class="Wdate"  value="<?php echo ($this->user_info ? $this->escapeHtml($this->user_info->user_birthday) : ''); ?>" ><label></label></td>
          </tr>
          <tr>
            <td class="label"><?php echo $this->translate('手机号码'); ?>
              <?php if ($userPhoneRegisterState == 'true') { ?>
                <span class="must_add_value">*</span>
              <?php } ?>
              ：</td><td><input style="width: 420px;" type="text" pattern="phone" <?php echo $userPhoneRegisterState == 'true' ? '' : 'empty=""'; ?> name="user_phone" id="user_phone" value="<?php echo ($this->user_info ? $this->escapeHtml($this->user_info->user_phone) : ''); ?>">
              <?php if($this->frontwebsite()->getIphoneSmsConfig('shop_phone_sms', 'phone_sms_type') and empty($this->user_info->user_phone)) { ?>
                &nbsp;&nbsp;<font color="red"><?php echo $this->translate('填写正确的手机号码，可以接收到商家的短信通知'); ?></font>
              <?php } ?>
            </td>
          </tr>
            <?php if($this->user_reg_extend['inputArray']) {
                foreach($this->user_reg_extend['inputArray'] as $exValue) {
                    ?>
                    <tr>
                        <td class="label">
                            <?php echo $this->escapeHtml($exValue['field_title']); ?>
                            <?php if(!empty($exValue['not_empty'])) { ?><font class="must_add_value">*</font><?php } ?>：
                        </td>
                        <td>
                            <?php if($exValue['field_type'] == 'radio' and !empty($exValue['body'])) {
                                foreach($exValue['body'] as $cKey => $g_b_value) {
                                    ?>
                                    <input type="radio" name="<?php echo $exValue['name']; ?>" <?php echo !empty($exValue['input_value']) ? ($exValue['input_value']==$g_b_value[0] ? 'checked' : '') : ($cKey == 0 ? 'checked' : ''); ?> value="<?php echo $g_b_value[0]; ?>"><?php echo $g_b_value[1]; ?>&nbsp;
                                <?php } } ?>

                            <?php if($exValue['field_type'] == 'select' and !empty($exValue['body'])) {
                                echo '<select name="'.$exValue['name'].'" id="'.$exValue['id'].'" '.(!empty($exValue['not_empty']) ? 'pattern="required" alt="'.$exValue['not_empty'].'"' : '').' class="span2">';
                                foreach($exValue['body'] as $g_b_value) {
                                    ?>
                                    <option value="<?php echo $g_b_value[0]; ?>" <?php if($g_b_value[0] == $exValue['input_value']) echo 'selected'; ?>><?php echo $g_b_value[1]; ?></option>
                                <?php } echo '</select>'; } ?>

                            <?php if($exValue['field_type'] == 'checkbox' and !empty($exValue['body'])) {
                                foreach($exValue['body'] as $g_b_value) {
                                    $checkedArray  = !empty($exValue['input_value']) ? explode(',', $exValue['input_value']) : array();
                                    ?>
                                    <input type="checkbox" name="<?php echo $exValue['name']; ?>[]" <?php echo (!empty($checkedArray) and in_array($g_b_value[0], $checkedArray)) ? 'checked' : ''; ?> value="<?php echo $g_b_value[0]; ?>"><?php echo $g_b_value[1]; ?>&nbsp;
                                <?php } } ?>

                            <?php if($exValue['field_type'] == 'text') { ?>
                                <span class="perfix fa"></span><input name="<?php echo $exValue['name']; ?>" id="<?php echo $exValue['id']; ?>" value="<?php echo $this->escapeHtml($exValue['input_value']); ?>" class="input" placeholder="<?php echo $exValue['field_title']; ?>" <?php if(!empty($exValue['not_empty'])) { ?>pattern="required"  alt="<?php echo $exValue['not_empty']; ?>"<?php } ?>>
                            <?php } ?>

                            <?php if($exValue['field_type'] == 'textarea') { ?>
                                <textarea name="<?php echo $exValue['name']; ?>" id="<?php echo $exValue['id']; ?>" <?php if(!empty($exValue['not_empty'])) { ?>pattern="required"  alt="<?php echo $exValue['not_empty']; ?>"<?php } ?>><?php echo $this->escapeHtml($exValue['input_value']); ?></textarea>
                            <?php } ?>

                            <?php if($exValue['field_type'] == 'upload') { ?>
                                <input type="file" name="<?php echo $exValue['name']; ?>" id="<?php echo $exValue['id']; ?>" <?php if(!empty($exValue['not_empty'])) { ?>pattern="required"  alt="<?php echo $exValue['not_empty']; ?>"<?php } ?>>
                            <?php } ?>
                        </td>
                    </tr>
                <?php } } ?>
          <tr>
            <td colspan="2" class="tc"><input type="submit" class="btn" value="<?php echo $this->translate('保存修改'); ?>"></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</div>
<script src="<?php echo $this->basePath('/public/css/dbblack/js/DatePicker/WdatePicker.js'); ?>"></script>
<script>
  $("input[name='user_email']").on("change",function(event){
    if(autoValidate.validate(event)){
      $.post("<?php echo $this->url('frontuser/default/user_id',array('action'=>'check','controller'=>'user','module'=>'user','check_type'=>'user_email','user_id'=>($this->user_info ? $this->user_info->user_id : '0'))); ?>",{user_email:$(this).val()},function(data){
        if(data == 'false') {
          autoValidate.showMsg({id:document.getElementById('user_email'),error:true,msg:'<?php echo $this->translate('该邮箱已经存在'); ?>'});
        }
      });
    }
  });
  $("input[name='user_phone']").on("change",function(event){
    if(autoValidate.validate(event)){
      $.post("<?php echo $this->url('frontuser/default/user_id',array('action'=>'check','controller'=>'user','module'=>'user','check_type'=>'user_phone','user_id'=>($this->user_info ? $this->user_info->user_id : '0'))); ?>",{user_phone:$(this).val()},function(data){
        if(data == 'false') {
          autoValidate.showMsg({id:document.getElementById('user_phone'),error:true,msg:'<?php echo $this->translate('该邮箱已经存在'); ?>'});
        }
      });
    }
  });
  function checkForm() {
      <?php
      if(isset($this->user_reg_extend['jsCheck']['jsCheckboxAndRadio']) and !empty($this->user_reg_extend['jsCheck']['jsCheckboxAndRadio'])) {
          echo implode('', $this->user_reg_extend['jsCheck']['jsCheckboxAndRadio']);
      } ?>
  }
</script>